package com.yunhe.tianhe.rentcars.service.cheliangguanli.impl;

import com.yunhe.tianhe.commons.dto.Pageable;
import com.yunhe.tianhe.rentcars.dao.cheliangguanli.WeiXiuDao;
import com.yunhe.tianhe.rentcars.dao.cheliangguanli.XinXiDao;
import com.yunhe.tianhe.rentcars.entity.cheliangguanli.WeiXiu;
import com.yunhe.tianhe.rentcars.entity.cheliangguanli.XinXi;
import com.yunhe.tianhe.rentcars.service.cheliangguanli.WeiXiuService;
import com.yunhe.tianhe.rentcars.service.cheliangguanli.XinXiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Service
public class XinXierviceImpl implements XinXiService {

    private Pageable<XinXi> pageable=new Pageable<>();
    @Autowired
    private XinXiDao xinXiDao;
    @Override
   @ResponseBody
    public Pageable findPage(Integer offset, Integer limit,String carcode,Integer carstate) {
        List<XinXi> list = xinXiDao.findPage1(offset,limit,carcode,carstate);
        int i = xinXiDao.findPage2();
        pageable.setRows(list);
        pageable.setTotal(Long.valueOf(i));
        return pageable;
    }

    @Override
    public Pageable Zuche(Integer offset, Integer limit) {
        List<XinXi> list = xinXiDao.Zuche1(offset,limit);
        if(list!=null){
            for(XinXi a:list){
                a.setBrandtype(a.getCarBrand()+a.getCarBrandType());
            }
        }
        int i = xinXiDao.Zuche2();
        pageable.setRows(list);
        pageable.setTotal(Long.valueOf(i));
        return pageable;
    }


    @Override
    public void save(XinXi xinXi) {
         xinXiDao.save(xinXi);
    }

    @Override
    public List<XinXi> findAll() {
      return   xinXiDao.findAll();
    }



    @Override
    public void deletebatch(String carids) {
        String[] arr = carids.split(",");
        for (String i:arr){
            this.delete(Long.valueOf(i));
        }
    }

    @Override
    public void delete(long carid) {
       xinXiDao.delete(carid);
    }

    @Override
    public XinXi find(long carid) {
        return xinXiDao.find(carid);
    }

    @Override
    public void update(XinXi xinXi) {
        xinXiDao.update(xinXi);
    }

    @Override
    public XinXi findid(String carcode) {
        return xinXiDao.findid(carcode);
    }
}
